import { quizService } from './../service/quizService';
import { useEffect, useState } from "react";

function formatDateKey(timestamp: number): string {
  const date = new Date(timestamp);
  return date.toISOString().split("T")[0]; // e.g. "2025-03-15"
}

export function useDailyProgress() {
  const [dailyCounts, setDailyCounts] = useState<number>(0);

  useEffect(() => {
    const fetchAndGroup = async () => {
      const history = await quizService.getDailyProgress();
      // const grouped: Record<string, number> = {};

      // history.forEach((item:any) => {
      //   const dateKey = formatDateKey(item.timestamp);
      //   grouped[dateKey] = (grouped[dateKey] || 0) + 1;
      // });

      setDailyCounts(history.length);
    };

    fetchAndGroup();
  }, []);

  return dailyCounts;
}
